package ch.bfh.android.WhereAmI;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {
	private Button btnTest;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		btnTest = (Button) findViewById(R.id.btnTest);
		btnTest.setOnClickListener(clickListener);
	}

	/** Creates the options menu */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle item selection
		switch (item.getItemId()) {
			case R.id.menuPreferences:
				Intent settingsActivity = new Intent(getBaseContext(),
						Preferences.class);
				startActivity(settingsActivity);
			default:
				return super.onOptionsItemSelected(item);
		}
	}

	OnClickListener clickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {

			Intent locationIntent = new Intent(
					"ch.bfh.android.WhereAmI.LOCATION_SERVICE");
			locationIntent.putExtra(LocationService.EXTRA_DISCOVER, true);
			locationIntent.putExtra(LocationService.EXTRA_SENDER, "");
			getApplicationContext().startService(locationIntent);
		}
	};

}
